<template>
  <div class="all">
    <button @click="changeValue(-1)">-</button>
    <input type="text" :value="value" @change="handleChange">
    <button @click="changeValue(1)">+</button>
  </div>
</template>

<script>
export default {
  props: {
    value: Number
  },
  methods: {
    changeValue (num) {
      if (this.value + num === 0) return
      this.$emit('input', this.value + num)
    },
    handleChange (e) {
      const num = +e.target.value
      if (!num || num <= 0) {
        e.target.value = this.value
        return
      }
      this.$emit('input', num)
    }
  }
}
</script>

<style scoped>
.all {
  display:flex;
}
.all button {
  width:40px;
  height:40px;
  text-align: center;
  line-height:40px;
}
.all input {
  width:40px;
  height:40px;
  text-align: center;
  line-height:40px;
}
</style>
